﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Syndication;
using System.ServiceModel.Web;
using System.Text;

namespace SyndicationService
{
    /// <summary>
    /// Interact with site content (i.e. Blogs and Recipes).  Getters are in the form of feeds
    /// </summary>
    [ServiceContract(Namespace = "PWS.SyndicationService")]
    [ServiceKnownType(typeof(Atom10FeedFormatter))]
    [ServiceKnownType(typeof(Rss20FeedFormatter))]
    public interface IContentService
    {

        [OperationContract(Name = "GetContent")]
        [WebGet(UriTemplate = "/content/{id}")]
        Content GetContent(string id);

        [OperationContract(Name = "GetContentByCategory")]
        [WebGet(UriTemplate = "/content/{category}?format={format}")]
        SyndicationFeedFormatter GetContentSyndicationFeed(string category, string format);

        [OperationContract(Name = "GetContentByDateRange")]
        [WebGet(UriTemplate = "/content/{category}?startDate={startDate}, endDate={endDate}, format={format}")]
        SyndicationFeedFormatter GetContentSyndicationFeed(string category, DateTime startDate, DateTime endDate, string format);

        [OperationContract]
        void AddContent(Content content);

        [OperationContract]
        void DeleteContent(int Id);
    }

    [DataContract]
    public class Content
    {
        [DataMember]
        public string Title { get; set; }

        [DataMember]
        public string Body { get; set; }

        [DataMember]
        public DateTimeOffset LastUpdatedTime { get; set; }

        [DataMember]
        public string ContentType { get; set; }

        [DataMember]
        public int Id { get; set; }
    }
}
